<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.1/umd/react.development.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.1/umd/react-dom.development.min.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
    <script type="text/babel">
      const { Component, createRef } = React;

      class Refs extends Component {
        /** 
         * constructor() {
           super();
           this.input2 = createRef();
           console.log(this);
         }
         */
        // 实例自身
        // input2 = createRef();
        showData = (e) => {
          console.log("createRef", this.input2.current);
          if (e.target.value) {
            alert(e.target.value);
          } else {
            alert(this.refs.input1.value);
          }
        };
        render() {
          return (
            <div>
              <input type="text" ref="input1" />
              <button onClick={this.showData}>show data</button>
              <input type="text" ref={this.input2} onBlur={this.showData} />
            </div>
          );
        }
      }

      const App = (
        <div>
          <Refs />
        </div>
      );
      ReactDOM.render(App, document.getElementById("root"));
    </script>
  </body>
</html>
